import Auth from '@/common/auth'
import Helper from '@/common/helper'
import Platform from '@/common/platform'
import Request from '@/common/request/index'
import mixin from '@/mixins'
import ROUTE from '@/router'
import store from '@/store'
import { createSSRApp } from 'vue'
import App from './App.vue'

import uvUI from '@climblee/uv-ui'

// scss主题色配置
import { primary } from '@/styles/theme.module.scss'

export function createApp() {
  const app = createSSRApp(App).use(store).use(uvUI).mixin(mixin)

  // 挂载工具函数
  app.config.globalProperties.$ROUTE = ROUTE
  app.config.globalProperties.$Helper = Helper
  app.config.globalProperties.$Env = Env
  app.config.globalProperties.$Platform = Platform
  app.config.globalProperties.$Auth = Auth
  app.config.globalProperties.$CDN = CDN
  app.config.globalProperties.$MAP = MAP

  // 直接可挂在到uni对象上
  uni.$ROUTE = ROUTE
  uni.$Auth = Auth

  // 需要在Vue.use(uvUI)之后执行
  uni.$uv.setConfig({
    config: {
      color: {
        'uv-primary': primary,
      },
    },
  })

  Request(app)
  return {
    app,
  }
}
